home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-20 / pmpsrc11.zip / PARAM.C < prev    next >
Text File  |  1991-07-30  |  10KB  |  479 lines

  1. /*
  2.     param.c -- Reads paramter file when program is started
  3.  
  4.   Poor Man's Packet (PMP)
  5.   Copyright (c) 1991 by Andrew C. Payne    All Rights Reserved.
  6.  
  7.   Permission to use, copy, modify, and distribute this software and its
  8.   documentation without fee for NON-COMMERCIAL AMATEUR RADIO USE ONLY is hereby
  9.   granted, provided that the above copyright notice appear in all copies.
  10.   The author makes no representations about the suitability of this software
  11.   for any purpose.  It is provided "as is" without express or implied warranty.
  12.  
  13.     August, 1989
  14.     Andrew C. Payne
  15. */
  16.  
  17. /* ---- Includes ----- */
  18. #include <stdio.h>
  19. #include <stdlib.h>
  20. #include <ctype.h>
  21. #include <string.h>
  22. #include <conio.h>
  23. #include <dos.h>
  24. #include "pmp.h"
  25. #include "ports.h"
  26.  
  27. static int     domycall(char *p),dotxdelay(char *p),dopthresh(char *p),
  28.         dofrack(char *p), doretry(char *p), donormal(char *p),
  29.         doinverse(char *p), dobright(char *p), dostatus(char *p),
  30.         dosound(char *p), doctext(char *p), dobtext(char *p),
  31.         dopttport(char *p), dotxport(char *p), docdport(char *p),
  32.         dorxport(char *p),docheck(char *p), domaxframe(char *p),
  33.         domessage(char *p), docapture(char *p), dodefine(char *p),
  34.         doinit(char *p), dobeacon(char *p), dobaddr(char *p),
  35.         doautowrap(char *p), dopaclen(char *p), doclock(char *p);
  36.  
  37. extern int SetAX25Addr(struct ax25_addr *p, char *c);
  38.  
  39. /* ----- Command list Structure ----- */
  40.  
  41. static struct param_cmd pcmds[] = {
  42.     { "mycall",    domycall },
  43.     { "txdelay",    dotxdelay },
  44.     { "pthresh",    dopthresh },
  45.     { "frack",    dofrack },
  46.     { "retry",    doretry },
  47.     { "normal",    donormal },
  48.     { "inverse",    doinverse },
  49.     { "bright",    dobright },
  50.     { "status",    dostatus },
  51.     { "message",    domessage },
  52.     { "sound",    dosound },
  53.     { "ctext",    doctext },
  54.     { "btext",     dobtext },
  55.     { "pttport",    dopttport },
  56.     { "txport",    dotxport },
  57.     { "cdport",    docdport },
  58.     { "rxport",    dorxport },
  59.     { "check",    docheck },
  60.     { "maxframe",    domaxframe },
  61.     { "capture",     docapture },
  62.     { "define",    dodefine },
  63.     { "init",    doinit },
  64.     { "beacon",    dobeacon },
  65.     { "baddr",    dobaddr },
  66.     { "autowrap",    doautowrap },
  67.     { "paclen",    dopaclen },
  68.     { "clockskew",    doclock },
  69.     { NULL,        NULL } };
  70.  
  71. static int    line;        /* current line number */
  72.  
  73. /* error()
  74.     Show error message.
  75. */
  76. void error(char *format, ...)
  77. {
  78.     char    s[100];
  79.     va_list    argptr;
  80.  
  81.     cprintf("Error on line %d in configuration file PMP.CFG :\r\n      ",line);
  82.     va_start(argptr, format);
  83.     vsprintf(s, format, argptr);
  84.     va_end(argptr);
  85.     cprintf(s);
  86. }
  87.  
  88. /* InitParameters()
  89.     Sets initial parameters.
  90. */
  91. void InitParameters()
  92. {
  93.     int    i;
  94.  
  95.     SetAX25Addr(&MyCall,"NOCALL");
  96.     TXStartFlags = 50;
  97.     TXEndFlags = 2;
  98.     Sound = FALSE;
  99.     Pthresh = 0;
  100.     Frack = 3;
  101.     Retry = 7;
  102.     MaxFrame = 7;
  103.     Sound = TRUE;
  104.     *btext = '\0';
  105.     strcpy(baddr, "CQ");
  106.     BeaconInt = 0;
  107.     nctexts = 0;
  108.     CaptureBuffer = 2048;
  109.     AutoWrap = 0;
  110.     Paclen = 128;
  111.     for(i=1; i<=10; i++)
  112.         *fkeys[i] = '\0';
  113.  
  114.     Ppersist = 12000;
  115.     Slottime = 2;
  116.     Pwait = 0;
  117.     ClockSkew = FALSE;
  118.  
  119. /* default I/O ports */
  120.     PTTPort = TXPort = 0x378;
  121.     TXBit = 1;
  122.     PTTBit = 2;
  123.  
  124.     CDPort = RXPort = 0x379;
  125.     RXBit = 8;
  126.     CDBit = 0x80;
  127.     CDLevel = 0;
  128. }
  129.  
  130. /* ReadParameters()
  131.     Opens and reads the parameter file.
  132.  
  133.     Returns TRUE if error.
  134. */
  135. int ReadParameters()
  136. {
  137.     FILE    *infile;
  138.     char    s[100];
  139.     char    cmd[80];
  140.     char    *p;
  141.     int    i;
  142.  
  143. /* open the file for input */
  144.     if((infile = fopen(ParamFname,"r")) == NULL) {
  145.         cprintf("Error -- Can't find configuration file '%s'   ",ParamFname);
  146.         return TRUE;
  147.     }
  148.  
  149. /* read through lines till end of file */
  150.     line = 0;
  151.     while(fgets(s,100,infile) != NULL) {
  152.         line++;
  153.         p = sob(s);
  154.         if(*p && *p != '#') {
  155.             i = dispatch(p, pcmds);
  156.             if(i == FAIL) {
  157.                 p = extract(p, cmd);
  158.                 error("Unknown command '%s'",cmd);
  159.             }
  160.             if(i) {
  161.                 fclose(infile);
  162.                 return TRUE;
  163.             }
  164.         }
  165.     }
  166.     fclose(infile);
  167.     return FALSE;
  168. }
  169.  
  170. /* ----- Command Handlers ----- */
  171.  
  172. /* domycall(s)
  173.     Sets the callsign of this node.
  174. */
  175. static int domycall(char *s)
  176. {
  177.     if(SetAX25Addr(&MyCall,s)) {
  178.         error("Invalid callsign");
  179.         return TRUE;
  180.     } else
  181.         return FALSE;
  182. }
  183.  
  184. /* dotxdelay(s)
  185.     Sets the transmitter delay.  This is the wait after the TX is keyed
  186.     and before data is sent.  The time is given in milliseconds.
  187. */
  188. static int dotxdelay(char *s)
  189. {
  190. /* convert time in ms to # of leading syncs */
  191.     TXStartFlags = max(2,(long)atoi(s) * 1200 / 8000);
  192.     return FALSE;
  193. }
  194.  
  195. /* dopthresh(s)
  196.     This parameter is a slight modification to AX.25 Version 2.0.  If
  197.     an I-packet has a data field smaller than this parameter, it is
  198.     always resent w/ a poll after a timeout, instead of polling w/ RR.
  199. */
  200. static int dopthresh(char *s)
  201. {
  202.     Pthresh = atoi(s);
  203.     return FALSE;
  204. }
  205.  
  206. /* dofrack(s)
  207.     This parameter is used to calculate the timeout time before retrying.
  208. */
  209. static int dofrack(char *s)
  210. {
  211.     Frack = atoi(s);
  212.     return FALSE;
  213. }
  214.  
  215. /* docheck(s)
  216.     This parameter is used as a keep-alive timer (in seconds).
  217. */
  218. static int docheck(char *s)
  219. {
  220.     Check = atoi(s);
  221.     return FALSE;
  222. }
  223.  
  224. /* doretry(s)
  225.     This parameter specifies the maximum number of retries before a
  226.     connection is dropped.
  227. */
  228. static int doretry(char *s)
  229. {
  230.     Retry = atoi(s);
  231.     return FALSE;
  232. }
  233.  
  234. /* domaxframe(s)
  235.     This parameter specifies the maximum number of frames allowed
  236.     outstanding (e.g. unACKed).
  237. */
  238. static int domaxframe(char *s)
  239. {
  240.     MaxFrame = atoi(s);
  241.     if(MaxFrame < 1 || MaxFrame > 7) {
  242.         error("MAXFRAME must be between 1 and 7");
  243.         return TRUE;
  244.     } else
  245.         return FALSE;
  246. }
  247.  
  248. /* donormal(s)
  249.     Sets the normal screen attribute.
  250. */
  251. static int donormal(char *s)
  252. {
  253.     NormalAttr = atoi(s);
  254.     return FALSE;
  255. }
  256.  
  257. /* doinverse(s)
  258.     Sets the inverse screen attribute.
  259. */
  260. static int doinverse(char *s)
  261. {
  262.     InvAttr = atoi(s);
  263.     return FALSE;
  264. }
  265.  
  266. /* dobright(s)
  267.     Sets the bright screen attribute
  268. */
  269. static int dobright(char *s)
  270. {
  271.     BrightAttr = atoi(s);
  272.     return FALSE;
  273. }
  274.  
  275. /* dostatus(s)
  276.     Sets the status line attribute
  277. */
  278. static int dostatus(char *s)
  279. {
  280.     StatusAttr = atoi(s);
  281.     return FALSE;
  282. }
  283.  
  284. /* domessage(s)
  285.     Sets the message line attribute
  286. */
  287. static int domessage(char *s)
  288. {
  289.     MsgAttr = atoi(s);
  290.     return FALSE;
  291. }
  292.  
  293. /* dosound(s)
  294.     Enables/disables sound.
  295. */
  296. static int dosound(char *s)
  297. {
  298.     Sound = atoi(s);
  299.     return FALSE;
  300. }
  301.  
  302. /* doctext(s)
  303.     Sets CTEXT lines, the connect welcome string.
  304. */
  305. static int doctext(char *s)
  306. {
  307.     if(nctexts >= MAXCTEXTS) {    /* check for too many lines */
  308.         error("Too many CTEXT lines.");
  309.         return TRUE;
  310.     }
  311.  
  312.     ctext[nctexts++] = strdup(s);
  313.     return FALSE;
  314. }
  315.  
  316. /* dobtext(s)
  317.     Sets btext, the beacon/CQ string.
  318.  
  319.     btext includes a carriage return.
  320. */
  321. static int dobtext(char *s)
  322. {
  323.     btext = strdup(s);
  324.     return FALSE;
  325. }
  326.  
  327. /* dopttport(s)
  328.     Sets the port and bit for the PTT output signal.
  329. */
  330. static int dopttport(char *s)
  331. {
  332.     PTTPort = strtoul(s, &s, 0);
  333.     s = sob(s);
  334.     PTTBit = strtoul(s, &s, 0);
  335.     s = sob(s);
  336.     PTTLevel = strtoul(s, &s, 0);
  337.     return FALSE;
  338. }
  339.  
  340. /* dotxport(s)
  341.     Sets the port and bit for the TX data line.
  342. */
  343. static int dotxport(char *s)
  344. {
  345.     TXPort = strtoul(s, &s, 0);
  346.     s = sob(s);
  347.     TXBit = strtoul(s, &s, 0);
  348.     return FALSE;
  349. }
  350.  
  351. /* docdport(s)
  352.     Sets the port and bit for the CD data line.
  353. */
  354. static int docdport(char *s)
  355. {
  356.     CDPort = strtoul(s, &s, 0);
  357.     s = sob(s);
  358.     CDBit = strtoul(s, &s, 0);
  359.     s = sob(s);
  360.     CDLevel = strtoul(s, &s, 0);
  361.     return FALSE;
  362. }
  363.  
  364. /* dorxport(s)
  365.     Sets the port and bit for the RX data line.
  366. */
  367. static int dorxport(char *s)
  368. {
  369.     RXPort = strtoul(s, &s, 0);
  370.     s = sob(s);
  371.     RXBit = strtoul(s, &s, 0);
  372.     return FALSE;
  373. }
  374.  
  375. /* docapture(s)
  376.     This buffer specifies the size of the capture buffer.  The larger this
  377.     number, the less disk writes required.  This number should be a multiple
  378.     of a sector size (512).
  379. */
  380. static int docapture(char *s)
  381. {
  382.     CaptureBuffer = atol(s);
  383.     if(CaptureBuffer < 512 || CaptureBuffer > 65536) {
  384.         error("CAPTURE must be between 512 and 65536 bytes");
  385.         return TRUE;
  386.     }
  387.     return FALSE;
  388. }
  389.  
  390. /* dodefine(s)
  391.     Defines function keys (F1 through F10).
  392. */
  393. static int dodefine(char *s)
  394. {
  395.     char    keyname[80];
  396.     int    keynumber;
  397.  
  398. /* extract function key */
  399.     s = extract(s, keyname);
  400.     keynumber = atoi(keyname + 1);
  401.     if(*keyname != 'f' || keynumber < 0 || keynumber > 10) {
  402.         error("Function key F1-F10 expected");
  403.         return TRUE;
  404.     }
  405.  
  406. /* extract key definition */
  407.     if(convertkey(fkeys[keynumber-1], s)) {
  408.         error("Error in definition for function key %s",keyname);
  409.         return TRUE;
  410.     } else
  411.         return FALSE;
  412. }
  413.  
  414. /* doinit(s)
  415.     Send an initializing byte value to a port upon startup.
  416. */
  417. static int doinit(char *s)
  418. {
  419.     word    port,value;
  420.  
  421.     port = strtoul(s, &s, 0);
  422.     s = sob(s);
  423.     value = strtoul(s, &s, 0);
  424.     outportb(port, value);
  425.     return FALSE;
  426. }
  427.  
  428. /* dobeacon(s)
  429.     Sets the interval for beaconing (in seconds).
  430. */
  431. static int dobeacon(char *s)
  432. {
  433.     BeaconInt = atoi(s);
  434.     return FALSE;
  435. }
  436.  
  437. /* dobaddr(s)
  438.     Sets the destination call and path for beacon packets.
  439. */
  440. static int dobaddr(char *s)
  441. {
  442.     baddr = strdup(s);
  443.     return FALSE;
  444. }
  445.  
  446. /* doautowrap(s)
  447.     Sets the column at which automatic word wrap is active.
  448. */
  449. static int doautowrap(char *s)
  450. {
  451.     AutoWrap = atoi(s);
  452.     if(AutoWrap && (AutoWrap < 10 || AutoWrap > 79)) {
  453.         error("AUTOWRAP must be zero or between 10 and 79 bytes");
  454.         return TRUE;
  455.     }
  456.     return FALSE;
  457. }
  458.  
  459. /* dopaclen(s)
  460.     Sets the maximum transmitted packet length.
  461. */
  462. static int dopaclen(char *s)
  463. {
  464.     Paclen = atoi(s);
  465.     if(Paclen < 1 || Paclen > 256) {
  466.         error("PACLEN must be between 1 and 256 bytes");
  467.         return TRUE;
  468.     }
  469.     return FALSE;
  470. }
  471.  
  472. /* doclock(s)
  473.     Enables or disables attempted clock skew adjust.
  474. */
  475. static int doclock(char *s)
  476. {
  477.     ClockSkew = atoi(s);
  478.     return FALSE;
  479. }